unit Unit10; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
  StdCtrls, sqldb, Unit1;

type

  { TForm10 }

  TForm10 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SQLQuery1: TSQLQuery;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormShow;
  private
    { private declarations }
  public
    codigo : string;
  end; 

var
  Form10: TForm10; 

implementation

{ TForm10 }

procedure TForm10.FormShow;
begin
  if SQLQuery1.Active = True then
    SQLQuery1.Close;

  Edit1.Text := '';
  Edit2.Text := '';
  Edit3.Text := '';

  if codigo <> '' then
  begin
    SQLQuery1.DataBase := Form1.PQConnection1;
    SQLQuery1.Transaction := Form1.SQLTransaction1;
    SQLQuery1.SQL.Text := 'select * from familia_producto where fmp_cdg = ' + codigo;

    SQLQuery1.Open;

    while not SQLQuery1.EOF do
    begin
      Edit2.Text := SQLQuery1.Fields[1].AsString;
      Edit3.Text := SQLQuery1.Fields[2].AsString;
      SQLQuery1.Next;
    end;

    Edit1.Text := codigo;

    SQLQuery1.Close;

    Edit2.SetFocus;
  end
  else
    Close;
end;

procedure TForm10.Button1Click(Sender: TObject);
var
  QueryString : String;

begin
  if Edit2.Text <> '' then
  begin
    QueryString := 'update familia_producto set fmp_nombre = ''' + Edit2.text + ''', fmp_descripcion = '''
      + Edit3.Text + ''' where fmp_cdg = ' + Edit1.Text;

    Form1.PQConnection1.ExecuteDirect('begin work;');
    Form1.PQConnection1.ExecuteDirect(QueryString);
    Form1.PQConnection1.ExecuteDirect('commit work;');

    ShowMessage('MODIFICACIÓN EXITOSA');
    Close;
  end
  else
    ShowMessage('ERROR EN EL INGRESO DE DATOS');
end;

procedure TForm10.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TForm10.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = True then
    SQLQuery1.Close;
end;

initialization
  {$I unit10.lrs}

end.

